package com.zhehekeji.opsys.api.webservice.server;

import javax.annotation.Resource;
import javax.jws.WebParam;
import javax.jws.WebService;
import javax.ws.rs.QueryParam;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zhehekeji.opsys.api.conf.Config;
import com.zhehekeji.opsys.api.resp.DateReportButtonLogListResp;
import com.zhehekeji.opsys.api.resp.DateReportListResp;
import com.zhehekeji.opsys.api.resp.DateReportOrderLogListResp;
import com.zhehekeji.opsys.api.resp.DateReportResp;
import com.zhehekeji.opsys.api.resp.DateReportSearchHisListResp;
import com.zhehekeji.opsys.api.resp.DateReportVodTimeListResp;
import com.zhehekeji.opsys.api.service.manager.IDataReportService;

/**
 * @author chenweiliu chenwei.liu@163.com
 * @ClassName DataReportWS
 * @Description TODO
 * @date 2015-3-26   上午11:23:50
 */
@WebService(endpointInterface = "com.zhehekeji.opsys.api.webservice.server.DataReport",
        name = "dataReport", portName = "dataReportPort", serviceName = "dataReportWS")
public class DataReportWS implements DataReport {
	private final static Logger logger = LoggerFactory.getLogger(DataReportWS.class);
	
	public static String MARK = "henan";

    @Resource(name = "dataReportService")
    private IDataReportService dataReportService;
    
    @Resource(name = "config")
	private Config config;

    public void setDataReportService(IDataReportService dataReportService) {
        this.dataReportService = dataReportService;
    }

	public void setConfig(Config config) {
		this.config = config;
	}

    public DateReportResp addVisitLog(String userID, String stb, String productCode, String productName, String cpID,
                                      int type, int resolution, String areaID, int epgPlatformType) {

        //return dataReportService.addVisitLog(userID, stb, productCode, productName, cpID, type, resolution, areaID, epgPlatformType);
        return null;
    }

    public DateReportResp addPageLog(String userID, String stb, int platformType, String cpID, int type, String pageIdentity, String pageName, String provinceIdentity, String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode, String categoryName,String operatorIdentity, String operatorName, String parentPageName, String utype, 
            String otype, String originRecommend, String ptype, String resolution) {
    	if(StringUtils.equals(config.getHenmark(), MARK)) {
        	logger.info("-----"+config.getHenmark());
        	return dataReportService.addPageLog(userID, stb, platformType, cpID, type, pageIdentity, pageName, "", "", provinceIdentity, provinceName, parentPageIdentity, contentCode, contentName, categoryCode, categoryName);
        }
    	return dataReportService.addVisitLog(userID, stb, platformType, cpID, type, pageIdentity, pageName, "", "", provinceIdentity, provinceName, parentPageIdentity, contentCode, contentName, categoryCode, categoryName,operatorIdentity, operatorName, parentPageName, utype, otype, originRecommend, ptype, resolution);
    }
    
    public DateReportListResp getPageLogList(String stb, String userID, int firstIndex, int maxResult) {    	
    	if(StringUtils.equals(config.getHenmark(), MARK)) {
    		logger.info("-----"+config.getHenmark());
    		return dataReportService.getPageLogListhn(stb, userID, firstIndex, maxResult);
    	}
    	return dataReportService.getPageLogList(stb, userID, firstIndex, maxResult);
    }
 
    public DateReportResp addButtonLog(String userID, String stb, int platformType, String cpID, int type, String pageIdentity, String pageName, String buttonIdentify, String buttonName, String provinceIdentity, String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode, String categoryName,String operatorIdentity, String operatorName, String parentPageName, String utype, 
            String otype, String originRecommend, String ptype, String resolution) {
    	if(StringUtils.equals(config.getHenmark(), MARK)) {
    		logger.info("-----"+config.getHenmark());
    		return dataReportService.addButtonLog(userID, stb, platformType, cpID, type, pageIdentity, pageName, buttonIdentify, buttonName, provinceIdentity, provinceName, parentPageIdentity, contentCode, contentName, categoryCode, categoryName);
        }
    	return dataReportService.addVisitLog(userID, stb, platformType, cpID, type, pageIdentity, pageName, buttonIdentify, buttonName, provinceIdentity, provinceName, parentPageIdentity, contentCode, contentName, categoryCode, categoryName,operatorIdentity, operatorName, parentPageName, utype, otype, originRecommend, ptype, resolution);
    }
    
    public DateReportButtonLogListResp getButtonLogList(String stb, String userID, int firstIndex, int maxResult) {
    	if(StringUtils.equals(config.getHenmark(), MARK)) {
    		logger.info("-----"+config.getHenmark());
    		return dataReportService.getButtonLogListhn(stb, userID, firstIndex, maxResult);
    	}
    	return dataReportService.getButtonLogList(stb, userID, firstIndex, maxResult);
    }

    public DateReportResp addVodLog(String userID, String contentCode, String contentName,
                                    String cpID, String productCode, int type, String seriesCode, String seriesName, String productName,
                                    int category, int resolution, String areaID, int epgPlatformType, String stb) {
        return dataReportService.addVodLog(userID, contentCode, contentName, cpID, productCode, type, seriesCode, seriesName, productName, category, resolution,
                areaID, epgPlatformType, stb);
    }

    public DateReportResp addVodTimeLog(String userID, String stb, int platformType, String cpID, int type, String pageIdentity, String pageName, String buttonIdentify, String buttonName, String provinceIdentity, String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode, String categoryName, Long playTime, String operatorIdentity, String operatorName,String utype,String ptype, String resolution) {
    	return dataReportService.addVodTimeLog(userID, stb, platformType, cpID, type,
                pageIdentity, pageName, provinceIdentity, provinceName, parentPageIdentity,
                contentCode, contentName, categoryCode, categoryName,
                playTime, "", "", operatorIdentity, operatorName,utype, ptype, resolution);
    }
    
    public DateReportVodTimeListResp getVodTimeLogList(String stb, String userID, int firstIndex, int maxResult) {
    	return dataReportService.getVodTimeLogList(stb, userID, firstIndex, maxResult);
    }

    public DateReportResp addOrderLog(String userID, int action, String stb, int platformType, String cpID, int type, String pageIdentity, String pageName, String buttonIdentify, String buttonName, String provinceIdentity, String provinceName, String parentPageIdentity, String contentCode, String contentName, String categoryCode, String categoryName, String operatorIdentity, String operatorName,String ptype, String resolution, String comFrom) {

        return dataReportService.addOrderLog(userID, stb, action, platformType, cpID, type, pageIdentity, pageName, provinceIdentity, provinceName, parentPageIdentity,
                contentCode, contentName, categoryCode, categoryName, 0d, 0d, operatorIdentity, operatorName, ptype, resolution, comFrom);
    }
    
    public DateReportOrderLogListResp getOrderLogList(String stb, String userID, int firstIndex, int maxResult) {
    	return dataReportService.getOrderLogList(stb, userID, firstIndex, maxResult);
    }


    public DateReportResp addComplainLog(String userID, String stb, String ip, String productCode, String productName,
                                         String cpID, int type, int resolution, String areaID, int epgPlatformType) {

        return dataReportService.addComplainLog(userID, stb, ip, productCode, productName, cpID, type, resolution, areaID, epgPlatformType);
    }

    public DateReportResp addPPVOrderLog(String userID, String contentCode, String contentName,
                                         double origPrice, double price, int resolution, int comeFrom, String cpID, String areaID, String productCode,
                                         String productName, int epgPlatformType, String stb) {

        return dataReportService.addPPVOrderLog(userID, contentCode, contentName, origPrice, price, resolution, comeFrom, cpID,
                areaID, productCode, productName, epgPlatformType, stb);

    }

    public DateReportResp addHomepageLog(String userID, String homepageCode, String homepageName,
                                         String location, int resolution, String cpID, String areaID, int epgPlatformType, String stb) {

        return dataReportService.addHomepageLog(userID, homepageCode, homepageName, location, resolution, cpID, areaID, epgPlatformType, stb);
    }

    public DateReportResp addSearchHisLog(String userID, String key, String code, String name, String pageNo, String poster, String operatorIdentity, String operatorName, String resolution) {
    	return dataReportService.addSearchHisLog(userID, key, code, name, pageNo, poster, operatorIdentity, operatorName, resolution);
    }
    
    public DateReportSearchHisListResp getSearchHisLog(String userID, int maxResult) {
    	return dataReportService.getSearchHisList(userID, maxResult);
    }
}
